<?php
    header("content-type:text/html;charset=utf-8");
    // $name = $_GET['username'];
    // $psw = $_GET['password'];
    $link = mysql_connect('localhost', 'root', 'root') or die('数据链接失败');
    mysql_select_db('fl',$link) or die('选择数据库失败');
    // $sql="select * from `goods`";
    $keyword = $_POST['keyword'];
    $id = $_POST['id'];

    $pagesize= isset($_POST['pagesize']) ? $_POST['pagesize'] :15;
    $page = isset($_POST['page']) ? $_POST['page'] : 1;
    $lowprice = $_POST['lowprice'];
    $sql = "select * from `goods`";
    
    
    if($id) $sql .= "where id=$id";
    if($keyword) $sql .= "where `good_name` LIKE '%$keyword%'";

    $res = mysql_query($sql);
     // 匹配就是$row就是一个resource
     // 匹配不上$row返回就是false boolean
    $arr8 = [];
    if($res){
        while($row = mysql_fetch_assoc($res)){
            array_push($arr8,$row);
        }
    }
 
    // $pagesize = 15;
    // 页码，默认 1

    // 开始行号
    $startRow = max(($page - 1), 0) * $pagesize;
    // 执行查询语句
    
    $result = mysql_query($sql);
    // 总条数
    $count = mysql_num_rows($result);
    // 总页数
    $pages = ceil($count / $pagesize);
    $sql .= " order by id asc limit {$startRow},{$pagesize}";
    // 再次执行查询语句  
    $result = mysql_query($sql);

    $response=array('count'=>'0','pages'=>'0','page'=>'0','data'=>'');
    $data = array(); 
    if($result){
        while($row = mysql_fetch_assoc($result)){
            array_push($data,$row);
           
        }
    };
    $response['count']=$count;
    $response['pages']=$pages;
    $response['page']=$page;
    $response['data']=$data;
  
   
    echo json_encode($response);

?>